﻿using TheLocal.Model;
using TheLocal.Tablet.Common;
using TheLocal.ViewModel;
using Windows.UI.Xaml.Controls;

// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238

namespace TheLocal.Tablet.Views
{
    /// <summary>
    /// An empty page that can be used on its own or navigated to within a Frame.
    /// </summary>
    public sealed partial class HomePage : LayoutAwarePage
    {
        CountryListViewModel countryListViewModel;

        public HomePage()
        {
            this.InitializeComponent();

            countryListViewModel = ViewModelLocator.HomePageViewModel.Countries;

            this.itemGridView.ItemsSource = countryListViewModel;
            this.itemListView.ItemsSource = countryListViewModel;
        }

        private ViewModelLocator ViewModelLocator
        {
            get
            {
                return (App.Current as App).ViewModelLocator;
            }
        }

        private void Country_ItemClick(object sender, ItemClickEventArgs e)
        {
            countryListViewModel.SelectedCountry = e.ClickedItem as Country;
            ViewModelLocator.NewsPageViewModel.SelectedCountry = countryListViewModel.SelectedCountry;
            this.Frame.Navigate(typeof(CategoryPage), null);
        }
    }
}
